package com.gao.config.exception;

import com.gao.util.ResultVO;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.nio.file.AccessDeniedException;

/**
 * @author gao
 * @time 2022/11/25 11:20:26
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(AccessDeniedException.class)
    public ResultVO handleAccessDeniedException(AccessDeniedException e) throws AccessDeniedException {
        // for debug，一般情况下要将异常信息写入日志文件
        e.printStackTrace();
        throw e;
    }

    @ExceptionHandler(Exception.class)
    public ResultVO handleException(Exception e) {
        // for debug，一般情况下要将异常信息写入日志文件
        e.printStackTrace();
        return ResultVO.failure(e.toString());
    }
}